<template>
  <view class="work-container">
    <!-- 轮播图 -->
    <uni-swiper-dot class="uni-swiper-dot-box" :info="data" :current="current" field="content">
      <swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
        <swiper-item v-for="(item, index) in data" :key="index">
          <view class="swiper-item" @click="clickBannerItem(item)">
            <image :src="item.image" mode="aspectFill" :draggable="false" />
          </view>
        </swiper-item>
      </swiper>
    </uni-swiper-dot>
 
	<uni-section title="工单系统" type="line"></uni-section>
	<view class="grid-body">
		<uni-grid :column="4" :showBorder="false">
		<uni-grid-item >
		  <view class="grid-item-box"  @click="goToOrderDetail('pending')">
			<view class="badge" v-if="pendingCount > 0">
			    <text class="badge-text">{{ pendingCount }}</text>
			</view>
			<uni-icons type="chat-filled" size="30"></uni-icons>
			<text class="text">待接单</text>
		  </view>
		</uni-grid-item>
		
		<uni-grid-item >
		  <view class="grid-item-box" @click="goToOrderDetail('repair')">
			<view class="badge" v-if="repairCount > 0">
			    <text class="badge-text">{{ repairCount }}</text>
			</view>
			<uni-icons type="bars" size="30"></uni-icons>
			<text class="text">待维修</text>
		  </view>
		</uni-grid-item>
	
		</uni-grid>
	</view>
	
	</view>
</template>

<script>
import { getWorkerOrder,getWorkerRepair } from "@/api/workerOrder.js"

export default {
    data() {
      return {
        current: 0,
        swiperDotIndex: 0,
		pendingCount: 0,
		repairCount: 0,
        data: [{
            image: '/static/images/banner/banner05.png'
          },
          {
            image: '/static/images/banner/banner06.png'
          },
          {
            image: '/static/images/banner/banner07.png'
          }
        ]
      }
    },
	onLoad() {
	    this.fetchPendingCount(); // 页面加载时查询待接单数量
	    this.fetchRepairCount(); // 页面加载时查询待接单数量
	},
    methods: {
      clickBannerItem(item) {
        console.info(item)
      },
      changeSwiper(e) {
        this.current = e.detail.current
      },
	  goToOrderDetail(type) {
		console.log(type);
	    switch (type) {
			case 'pending':
				const workerId = 100;
				uni.navigateTo({
					url: '/pages/OrderDetail/OrderDetail'
				});
				break;
			case 'repair':
				uni.navigateTo({
					url: '/pages/OrderDetail/OrderRepair'
				});
				break;
			}
		},
		fetchPendingCount() {
		    getWorkerOrder(100).then(response=>{
				this.pendingCount = response.data.length;
			}); 
		},
		fetchRepairCount() {
		    getWorkerRepair(100).then(response=>{
				this.repairCount = response.data.length;
			});
		}
	}
  }
</script>

<style lang="scss" scoped>
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }
  /* #endif */

  .text {
    text-align: center;
    font-size: 26rpx;
    margin-top: 10rpx;
  }

  .grid-item-box {
    flex: 1;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 0;
  }

  .uni-margin-wrap {
    width: 690rpx;
    width: 100%;
    ;
  }

  .swiper {
    height: 300rpx;
  }

  .swiper-box {
    height: 150px;
  }

  .swiper-item {
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    height: 300rpx;
    line-height: 300rpx;
  }

  @media screen and (min-width: 500px) {
    .uni-swiper-dot-box {
      width: 400px;
      /* #ifndef APP-NVUE */
      margin: 0 auto;
      /* #endif */
      margin-top: 8px;
    }

    .image {
      width: 100%;
    }
  }
  
  .grid-item-box {
    position: relative; /* 设置为相对定位，以便角标可以相对于它进行绝对定位 */
    /* 其他样式保持不变 */
  }
  
  .badge {
    position: absolute; /* 绝对定位 */
    top: 0; /* 位于容器顶部 */
    right: 0; /* 位于容器右侧 */
    background-color: red; /* 红色背景 */
    color: white; /* 白色文字 */
    border-radius: 50%; /* 圆形角标 */
    padding: 4px; /* 内边距，根据需要调整 */
    min-width: 20px; /* 最小宽度，根据需要调整 */
    height: 20px; /* 高度，与宽度相同以保持圆形 */
    display: flex; /* 使用flex布局使文字居中 */
    align-items: center; /* 垂直居中 */
    justify-content: center; /* 水平居中 */
    font-size: 12px; /* 文字大小，根据需要调整 */
    box-sizing: border-box; /* 包含内边距和边框在内的总宽度和高度 */
  }

  
  
</style>
